package com.itheima.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

@Controller
// 类上定义请求映射
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/save")
    // http://localhost/save?name=itheima&age=14
    public String save(String name, int age){
        System.out.println(age + "岁的" + name);
        return "/success.jsp";
    }

    @RequestMapping("/r1")
    //  http://localhost/r1?name=itheima&name=cb
    public String r1(String[] name){
        System.out.println(name[0] + name[1]);
        return "/success.jsp";
    }

    @RequestMapping("/r2")
    //  http://localhost/r2?name=itheima&name=cb
    public  String r2(@RequestParam("name") List<String> name){
        System.out.println(name);
        return "/success.jsp";
    }

    @RequestMapping("/r3")
    //  http://localhost/r3?date=2021/06/01
    public  String r3(Date date){
        System.out.println(date);
        return "/success.jsp";
    }

    // 在类上定义时，要在页面路径前加 /
    @RequestMapping("/r4")
    public String r4(){
        System.out.println("123");
        return "/success.jsp";
    }

    // 转发页面跳转
    @RequestMapping("/r5")
    public String r5(){
        System.out.println("123");
        return "forward:/success.jsp";
    }

    // 重定向页面跳转
    @RequestMapping("/r6")
    public String r6(){
        System.out.println("123");
        return "redirect:/success.jsp";
    }
}
